package com.example.springvue.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.springvue.common.utils.PageUitl;
import com.example.springvue.mapper.AdminLogMapper;
import com.example.springvue.model.AdminLog;
import com.example.springvue.service.AdminLogService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@Service
public class AdminLogServiceImpl implements AdminLogService {
    @Resource
    private AdminLogMapper adminLogMapper;


    @Override
    public boolean Add(AdminLog adminLog) {
        adminLog.setCreateTime(new Timestamp(System.currentTimeMillis()));
        int add = adminLogMapper.insert(adminLog);
        if (add==1){
            return true;
        }
        return false;
    }

    public Map<String,Object> getList(int pageSize, int page,Map<String,Object> map){
        PageHelper.startPage(page,pageSize);

        QueryWrapper<AdminLog> wrapper = new QueryWrapper<>();
        wrapper.lambda().gt(AdminLog::getId,0);
        wrapper.lambda().orderByDesc(AdminLog::getId);

        List<Map<String,Object>> list  =  adminLogMapper.selectMaps(wrapper);
        Map<String ,Object> data = PageUitl.page(list,pageSize,page);
        return data;

    }
}
